<!DOCTYPE HTML>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
	<meta name="format-detection" content="telephone=no,email=no,date=no,aItemress=no">
	<title>修改手机号</title>
	<link rel="stylesheet" type="text/css" href="../../css/aui.css" />
	<link rel="stylesheet" type="text/css" href="../../css/app.css" />
	<style type="text/css">
		body {
			background-color: #F5F5F5;
		}

		.aui-bar-nav .aui-pull-left {
			padding: 0 0.25rem;
		}

		.aui-list {
			padding: 0 .85rem;
		}

		.aui-title {
			font-size: .9rem;
			font-family: PingFangSC-Regular;
			font-weight: 400;
			color: rgba(34, 34, 34, 1);
		}

		.aui-list-item- {
			height: 2.5rem;
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			align-items: center;
		}

		.aui-list-item-label- img {
			width: 1rem;
		}

		.aui-btn-block {
			width: 17.25rem;
			height: 2rem;
			line-height: 2rem;
			text-align: center;
			background: linear-gradient(135deg, rgba(132, 229, 255, 1) 0%, rgba(107, 180, 255, 1) 100%, rgba(122, 174, 229, 1) 100%);
			border-radius: 1.25rem;
			margin-left: 50%;
			transform: translateX(-50%);
			font-size: .8rem;
			font-family: PingFangSC-Regular;
			font-weight: 400;
			color: #fff;
			/*background: linear-gradient(-152deg, #ff00ff, #9b00ff);*/
			/*background: linear-gradient(270deg, #ff00ff, #9471da);*/
			/*background: linear-gradient(270deg, #ee02fd, #9972e6);*/
		}

		.aui-btn {
			/*border-radius: 0.25rem;*/
		}

		::placeholder {
			font-size: .75rem;
			font-family: PingFangSC-Regular;
			font-weight: 400;
			color: rgba(187, 187, 187, 1);
		}

		.wraper {
			padding: 0 0.75rem;
			background: #ffffff;
		}

		.wraper>div:nth-child(1) {
			/*padding: 1.35rem 0 0 0;*/
			height: 3.25rem;
			border-bottom: 1px solid rgba(238, 238, 238, 0.5);
		}

		.wraper>div:nth-child(2) {
			height: 2.75rem;
			display: flex;
			justify-content: space-between;
			align-items: center;
		}

		.next_btn {
			width: 17.25rem;
			height: 2.3rem;
			background: #005A93;
			border-radius: 0.3rem;
			text-align: center;
			line-height: 2.3rem;
			margin: 2rem auto;
			opacity: 0.29;
		}

		.bg_opacity {
			opacity: 1
		}
		.aui-text-linear{
			color:#fff
		}
	</style>
</head>

<body>
	<div id="aui-header" class="ming-bg-blue">
		<header class="aui-bar aui-bar-nav ming-bg-blue aui-border-b">
			<a class="aui-pull-left" tapmode onclick="close_win()" style="margin-left:.75rem;">
				<img class="btn-img-back" src="../../image/btn/btn-back.png" />
			</a>
			<div class="aui-title">
				<div class="aui-text-linear">
					修改手机号
				</div>
			</div>
		</header>
	</div>
	<div class="" id="app" v-cloak="">
		<!-- {{info.mobile}} -->
		<div class="wraper">
			<div class="">
				<!-- <span style="font-size:0.75rem;font-family:PingFangSC-Regular;font-weight:400;color:rgba(34,34,34,1);line-height:1.05rem;">{{info.mobile}}</span> -->
				<input style="font-size:0.75rem;font-family:PingFangSC-Regular;font-weight:400;color:rgba(34,34,34,1);line-height:1.05rem;height:3.25rem;height:auto;padding-top:1.35rem;" v-model="mobile" type="tel" maxlength="11" placeholder="请输入手机号" />
			</div>
			<div class="">
				<input v-model="sms_code" type="tel" maxlength="6" placeholder="请输入验证码" style="width:60%;" />
				<div class="" style="display:flex;justify-content:space-between;align-items:center">
					<span style="font-size:0.75rem;font-family:PingFangSC-Regular;font-weight:400;color:rgba(0,90,147,0.5);opacity:0.29;">{{sms_time}}</span>

					<div class="code" v-if="sms_time" style="font-size:0.75rem;font-family:PingFangSC-Regular;font-weight:400;color:rgba(0,90,147,0.5);margin-left:0.6rem;opacity:0.29;">
						获取验证码
					</div>
					<div v-else class="" tapmode onclick="getCode()" style="font-size:0.75rem;font-family:PingFangSC-Regular;font-weight:400;color:rgba(0,90,147,1);margin-left:0.6rem;">
						获取验证码
					</div>

				</div>
			</div>
		</div>

		<!-- 下一步按钮 -->
		<div class="next_btn" style="font-size:0.8rem;font-family:PingFangSC-Regular;font-weight:400;color:rgba(255,255,255,1);" tapmode onclick="updateMobile()" :class="{'bg_opacity':mobile!=''&&sms_code!=''}">
			下一步
		</div>


	</div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/vue.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script type="text/javascript" src="../../script/verify.js"></script>
<script>
	var vm = new Vue({
		el: "#app",
		data: {
			mobile: '',
			sms_code: '',
			sms_time: '',
			info: {}
		},
		methods: {
			get_userinfo: function() {
				get_data('api/user/getUserInfo', {
					token: $api.getStorage('token')
				}, function(ret) {
					if (ret.status) {
						save_userinfo_new(ret)
						vm.mobile = ret.data.mobile
					}
				}, false)
			}
		}
	})
	apiready = function() {
		vm.get_userinfo();
		$api.fixStatusBar($api.byId('aui-header'))
		api.setStatusBarStyle({
			style: 'dark'
		});
	};

	function getCode() {
		if (vm.sended) {
			return;
		}
		if (!isPoneAvailable(vm.mobile)) {
			toast('请输入正确的手机号')
			return;
		}
	
		get_data('api/Sms/sendAuthCode', {
			mobile: vm.mobile,
		}, function(ret) {
			//从服务器请求验证码并返回结果，如果已发送操作如下：				
			vm.sended = 1;
			var timer = 60;
			vm.sms_time = timer + 's'
			var ti = setInterval(function() {
				timer = timer - 1;
				vm.sms_time = timer + 's';
				if (timer < 0) {
					vm.sended = 0;
					vm.sms_time = '';
					clearInterval(ti);
				}
			}, 1000);
			toast(ret.msg)
		})
	}

	function updateMobile() {
		if (vm.sms_code == '' || vm.mobile == '') {
			return;
		}
		if (vm.sms_code.length != 6) {
			toast('验证码错误');
			return;
		}
		if (!isPoneAvailable(vm.mobile)) {
			toast('请输入正确的手机号')
			return;
		}
		get_data('api/user/updateMobile', {
			token: $api.getStorage('token'),
			old_mobile: vm.mobile,
			authCode: vm.sms_code,
			flag: '1'
		}, function(ret) {
			if (ret.status) {
				open_win('./change_phone_step2', './change_phone_step2.html', false)
				setTimeout(function() {
					close_win()
				}, 1000)
			} else {
				toast(ret.msg)
			}
		})
	}
</script>

</html>
